package io.ouka.pub.vo;


import javax.validation.constraints.NotNull;
import java.util.Objects;

/**
 * @author ouka
 * @ClassName PageVo
 * @Package com.sinosig.pub.vo
 * @Description: TODO
 * @date 2020/5/28 17:25
 */
public class PageVo<T> {
    private Integer count;
    private Integer pageSize;
    private Integer pageNum;
    private Integer totalPage;
    private Integer prePage;
    private Integer nextPage;
    private T data;
    public PageVo(@NotNull Integer pageSize, @NotNull Integer pageNum, @NotNull Integer count, T data) {
        if (!Objects.isNull(data)) {
            this.data=data;
        }
        this.init(pageSize, pageNum, count);
    }

    private void init(Integer pageSize, Integer pageNum, Integer count) {
        this.pageSize = pageSize;
        this.pageNum = pageNum;
        this.count = count;
        this.totalPage = count % pageSize == 0 ? count / pageSize : count / pageSize + 1;
        this.prePage = pageNum == 1 ? null : pageNum - 1;
        this.nextPage = pageNum == totalPage ? null : pageNum + 1;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getPrePage() {
        return prePage;
    }

    public void setPrePage(Integer prePage) {
        this.prePage = prePage;
    }

    public Integer getNextPage() {
        return nextPage;
    }

    public void setNextPage(Integer nextPage) {
        this.nextPage = nextPage;
    }
}
